package com.ruoyi.framework.aspectj;

import com.ruoyi.framework.field.RequestsParamCheckHandel;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * 请求参数拦截器
 *
 * @author ruoyi
 */
@Aspect
@Component
public class RequestsAspect {

    @Resource
    private HttpServletRequest request;
    private static final Logger log = LoggerFactory.getLogger(RequestsAspect.class);


    /**
     * get请求前执行
     */
    @Before(value = "@annotation(getMapping)")
    public void getBefore(JoinPoint joinPoint, GetMapping getMapping) {
        RequestsParamCheckHandel.check(request);
    }

    /**
     * post请求前执行
     */
    @Before(value = "@annotation(mapping)")
    public void postBefore(JoinPoint joinPoint, PostMapping mapping) {
        RequestsParamCheckHandel.check(request);
    }

    /**
     * post请求前执行
     */
    @Before(value = "@annotation(mapping)")
    public void putBefore(JoinPoint joinPoint, PutMapping mapping) {
        RequestsParamCheckHandel.check(request);
    }

    /**
     * post请求前执行
     */
    @Before(value = "@annotation(mapping)")
    public void deleteBefore(JoinPoint joinPoint, DeleteMapping mapping) {
        RequestsParamCheckHandel.check(request);
    }

    /**
     * post请求前执行
     */
    @Before(value = "@annotation(mapping)")
    public void requestsBefore(JoinPoint joinPoint, RequestMapping mapping) {
        RequestsParamCheckHandel.check(request);
    }

}
